package client.comm.baoding.adapter.page

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import client.comm.baoding.fragment.ZcjlOneFragment
import client.comm.baoding.fragment.ZcjlThreeFragment
import client.comm.baoding.fragment.ZcjlTwoFragment

class MxjlFragmentPageAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {

    val fragments: Array<Fragment?> by lazy {
        arrayOfNulls(2)
    }

    override fun getItem(position: Int): Fragment {
        if (position == 0 && fragments[0] == null) {
            fragments[0] = ZcjlOneFragment()
        }
//        else if (position == 1 && fragments[1] == null) {
//            fragments[1] = ZcjlTwoFragment()
//        }
        else if (position == 1 && fragments[1] == null) {
            fragments[1] = ZcjlThreeFragment()
        }
        /*else if (position == 2 && fragments[2] == null) {
            fragments[2] = ZcjlFourFragment()
        } else if (position == 3 && fragments[3] == null) {
            fragments[3] = ZcjlFiveFragment()
        }*/
        return fragments[position]!!
    }

    override fun getCount(): Int {
        return fragments.size
    }

    override fun getPageTitle(position: Int): CharSequence? {

        return when (position) {
            0 -> "余额"
//            1 -> "可提余额"
            else -> "积分"
        }
    }
}